package gui.panel_new.conexion;

import enums.TextBundleEnum;
import enums.URLEnum;
import misc.BundlesProvider;
import model.eval.Test;

import javax.swing.*;
import java.awt.*;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Extension de JPanel destinado a poder crear un servidor para el envio y recepcion de evaluaciones;
 *
 * @author Jose Martin Rozanec;
 */
public class ServerConnectionPanel extends JPanel {
    private JLabel selectedTestLabel;
    private JTextField selectedTestField;
    private JTextArea testOverviewArea;
    private JLabel ipLabel;
    private JTextField ipField;
    private JLabel studentsToEvaluateLabel;
    private JTextField studentsToEvaluateField;
    private JButton startButton;
    private JTextArea connectedTextArea;

    private ResourceBundle textBundle;

    private Test test;

    /**
     * Constructor;
     */
    public ServerConnectionPanel() {
        initComponents();
        layoutComponents();
        setEditables();
    }

    /**
     * Inicializa los componentes del ServerConnectionPanel;
     */
    private void initComponents() {
        textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        selectedTestLabel = new JLabel(textBundle.getString(TextBundleEnum.SELECTED_TEST.toString()));
        selectedTestField = new JTextField(20);
        testOverviewArea = new JTextArea(10, 50);
        testOverviewArea.setBorder(BorderFactory.createTitledBorder(
                BorderFactory.createLineBorder(Color.BLACK), textBundle.getString(TextBundleEnum.TEST.toString())));
        ipLabel = new JLabel(textBundle.getString(TextBundleEnum.IP.toString()));
        ipField = new JTextField(15);
        studentsToEvaluateLabel = new JLabel(textBundle.getString(TextBundleEnum.STUDENTS_TO_BE_EVALUATED.toString()));
        studentsToEvaluateField = new JTextField(15);
        startButton = new JButton(textBundle.getString(TextBundleEnum.START.toString()));
        connectedTextArea = new JTextArea(10, 50);
        connectedTextArea.setBorder(BorderFactory.createTitledBorder(
                BorderFactory.createLineBorder(Color.BLACK), textBundle.getString(
                TextBundleEnum.CONNECTED_STUDENTS.toString())));
    }

    /**
     * Dispone los elementos visuales del ServerConnectionPanel;
     */
    private void layoutComponents() {
        int x = 0;
        int y = 0;
        setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        JPanel panel1 = new JPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        panel1.add(selectedTestLabel, constraints);
        constraints.gridx = 1;
//        gridBagConstraints.gridx=++x;
        panel1.add(selectedTestField, constraints);
        add(panel1, gridBagConstraints);

        gridBagConstraints.gridheight = 3;
        gridBagConstraints.gridwidth = 2;
//        gridBagConstraints.gridx=--x;
        gridBagConstraints.gridy = ++y;
        add(testOverviewArea, gridBagConstraints);
        gridBagConstraints.gridheight = 1;
        gridBagConstraints.gridwidth = 1;
        y = 3;
        gridBagConstraints.gridy = ++y;
        JPanel panel = new JPanel(new GridBagLayout());
        constraints = new GridBagConstraints();
        panel.add(ipLabel, constraints);
        constraints.gridx = 1;
//        gridBagConstraints.gridx=++x;
        panel.add(ipField, constraints);
//        gridBagConstraints.gridx=--x;
//        gridBagConstraints.gridy=++y;
        constraints.gridx = 2;
        panel.add(studentsToEvaluateLabel, constraints);
//        gridBagConstraints.gridx=++x;
        constraints.gridx = 3;
        panel.add(studentsToEvaluateField, constraints);
//        gridBagConstraints.gridx=--x;
        add(panel, gridBagConstraints);
        gridBagConstraints.gridy = ++y;
        add(startButton, gridBagConstraints);
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridy = ++y;
        add(connectedTextArea, gridBagConstraints);
    }

    /**
     * Establece un conjunto de JTextFields como no editables;
     */
    private void setEditables() {
        ipField.setEditable(false);
        selectedTestField.setEditable(false);
        testOverviewArea.setEditable(false);
        connectedTextArea.setEditable(false);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setContentPane(new ServerConnectionPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
